package logic

import (
	"context"
	"errors"
	"srv/house"
	"srv/internal/svc"
	"srv/models"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserStatusLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserStatusLogic {
	return &UserStatusLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserStatusLogic) UserStatus(in *house.UserStatusRequest) (*house.UserStatusResponse, error) {
	// todo: add your logic here and delete this line
	var newUser models.User
	err := newUser.FirstUser(int(in.UserId))
	if err != nil {
		logx.Error("账号未登录,不允许审核")
		return nil, errors.New("账号未登录,不允许审核")
	}
	user := models.User{
		Status: int(in.Status),
	}
	err = user.UpUser(int(in.UserId))
	if err != nil {
		logx.Error("网络异常,审核失败")
		return nil, errors.New("网络异常,审核失败")
	}
	return &house.UserStatusResponse{}, nil
}
